/*
 * @Description:
 * @Author: dh
 * @Date: 2021-09-28 14:19:19
 * @LastEditors: dh
 * @LastEditTime: 2021-09-28 17:49:32
 */

self.addEventListener('install', event => {
	console.log('正在注册sw1')
})

self.addEventListener('activate', event => {
	console.log('正在激活sw1')
})

self.addEventListener('message', event => {
	console.log('sw1-收到消息', event.data)

	// 方法一 (不过这种方法只能向消息的来源页面发送信息。)
	event.source.postMessage('this message is from sw1.js, to page')

	// 方法二 (this.clients 来获取其他的页面，没实验成功)
	// this.clients.matchAll().then(client => {
	//     console.log(client);
	// client[0].postMessage('this message is from sw.js, to page');
	// })
})
